package com.turing.post.organization.impl;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.common.util.PCPSCommonDao;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.organization.util.IssueCompany;
import com.turing.post.organization.util.IssueCompanyDao;
import com.turing.post.organization.util.OrganApplicationException;
import com.turing.post.organization.util.OrganRespCode;
import com.turing.post.organization.util.SysBranch;
import com.turing.post.organization.util.SysBranchDao;
import com.turing.post.organization.util.Voucher;
import com.turing.post.organization.util.VoucherDao;
import com.turing.post.organization.util.VoucherOrderActionDetail;
import com.turing.post.organization.util.VoucherOrderActionDetailDao;
import com.turing.post.organization.util.VoucherStock;
import com.turing.post.organization.util.VoucherStockBusiness;
import com.turing.post.organization.util.VoucherStockDao;
import com.turing.post.organization.util.VoucherStockDetail;
import com.turing.post.organization.util.VoucherStockDetailBusiness;
import com.turing.post.organization.util.VoucherTransferOrder;
import com.turing.post.organization.util.VoucherTransferOrderBusiness;
import com.turing.post.organization.util.VoucherTransferOrderDao;
import com.turing.post.organization.util.VoucherTransferOrderDetail;
import com.turing.post.organization.util.VoucherTransferOrderDetailBusiness;
import com.turing.post.organization.util.VoucherTransferOrderDetailDao;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSUtil;
import com.turing.post.util.PCPSWebInput;

/**
 * @author wzd
 * @Dec 18, 2012
 */
@Stateless(mappedName = "organization.impl.VoucherTransferOrderBusinessImpl")
@Remote
@Local
public class VoucherTransferOrderBusinessImpl implements
		VoucherTransferOrderBusiness {

	@EJB(mappedName = "organization.impl.VoucherTransferOrderDaoImpl")
	private VoucherTransferOrderDao voucherTransferOrderDaoImpl;// 凭证调拨单

	@EJB(mappedName = "organization.impl.VoucherTransferOrderDetailBusinessImpl")
	private VoucherTransferOrderDetailBusiness voucherTransferOrderDetailBusinessImpl;// 凭证调拨单明细业务

	@EJB(mappedName = "organization.impl.VoucherTransferOrderDetailDaoImpl")
	private VoucherTransferOrderDetailDao voucherTransferOrderDetailDaoImpl;// 凭证调拨单明细

	@EJB(mappedName = "common.impl.PCPSCommonDaoImpl")
	private PCPSCommonDao pcpsCommonDaoImpl;// 主键

	@EJB(mappedName = "organization.impl.IssueCompanyDaoImpl")
	private IssueCompanyDao issueCompanyDaoImpl;// 发卡商

	@EJB(mappedName = "organization.impl.SysBranchDaoImpl")
	private SysBranchDao sysBranchDaoImpl;// 序号

	@EJB(mappedName = "organization.impl.VoucherStockDaoImpl")
	private VoucherStockDao voucherStockDaoImpl;// 凭证库存

	@EJB(mappedName = "organization.impl.VoucherStockBusinessImpl")
	private VoucherStockBusiness voucherStockBusinessDaoImpl;// 凭证库存业务

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;// 日志getSysBranchByBranchNo

	@EJB(mappedName = "organization.impl.VoucherOrderActionDetailDaoImpl")
	private VoucherOrderActionDetailDao voucherOrderActionDetailDaoImpl;// 迁移明细

	@EJB(mappedName = "organization.impl.VoucherDaoImpl")
	private VoucherDao voucherDaoImpl;// 凭证种类表

	@EJB(mappedName = "organization.impl.VoucherStockDetailBusinessImpl")
	private VoucherStockDetailBusiness voucherStockDetailBusinessDaoImpl;// 凭证库存详细业务
	/**
	 * 新增凭证调拨单
	 * 
	 * @param VoucherTransferOrder
	 *            凭证调拨单
	 * @throws PCPSApplicationException
	 */
	public BigInteger insertVoucherTransferOrder(PCPSWebInput webInput,
			VoucherTransferOrder voucherTransferOrder,
			List<VoucherTransferOrderDetail> datil)
			throws PCPSApplicationException {
		// 登录用户机构号为空
		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户机构号为NULL");
		}
		// 验证调出机构
		SysBranch branchform = sysBranchDaoImpl.getSysBranchByBranchNo(webInput
				.getOperBranchNo());
		if (branchform.getBranchType().equals(SysBranch.SYSBRANCH_ISSUECOMPANY)) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调出机构不是机构!");
		}
		// 调入机构号
		if (PCPSUtil.isEmpty(voucherTransferOrder.getToBranchNo())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调入机构号为空!");
		}
		// 验证调入机构
		SysBranch branchto = sysBranchDaoImpl
				.getSysBranchByBranchNo(voucherTransferOrder.getToBranchNo());
		if (!branchto.getBranchType().equals(SysBranch.SYSBRANCH_SALEBRANCH)
				&& !branchto.getBranchType().equals(
						SysBranch.SYSBRANCH_ISSUEBRANCH)) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调入机构不是机构!");
		}
		// 操作员
		if (webInput.getOperId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"操作员为空!");
		}
		// 得到调拨单ID
		BigInteger transferOrderId = pcpsCommonDaoImpl.getUniqueIntegerKey();
		if (transferOrderId == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"插入失败得到调拨单ID为空!");
		}
		// 发卡商
		IssueCompany ic = issueCompanyDaoImpl
				.getIssueCompanyByIssueCompanyNo(webInput.getOperBranchNo()
						.substring(0, 6));
		Integer seqNo = sysBranchDaoImpl.updateSysBranchOrderSeqNo(webInput
				.getOperBranchNo());
		// 业务单号
		String orderSeqNo = webInput.getOperBranchNo()
				+ PCPSUtil.getPackedYMDString(ic.getTranDate())
				+ String.format("%05d", seqNo);
		if (PCPSUtil.isEmpty(orderSeqNo)) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"业务单号为空!");
		}
		voucherTransferOrder.setTransferOrderId(transferOrderId);
		voucherTransferOrder.setIssueCompanyNo(webInput.getOperBranchNo()
				.substring(0, 6));
		voucherTransferOrder.setFromBranchNo(webInput.getOperBranchNo());
		voucherTransferOrder.setOrderSeqNo(orderSeqNo);

		// 入库时间
		voucherTransferOrder
				.setTranTime(pcpsCommonDaoImpl.getDatabaseSysTime());
		// 操作员号
		voucherTransferOrder.setOperId(webInput.getOperId());
		// 状态
		voucherTransferOrder.setStatus(VoucherTransferOrder.Status_0);
		// 插入凭证调拨单
		voucherTransferOrderDaoImpl
				.insertVoucherTransferOrder(voucherTransferOrder);
		// 凭证入库单明细
		int j = 1;
		HashMap<String, String> startseqmap = new HashMap<String, String>();
		HashMap<String, String> endseqmap = new HashMap<String, String>();
		VoucherTransferOrderDetail Datil=null;
		if(datil==null || datil.size()==0){
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
					"", "凭证号段为空!");
		}
		VoucherStockDetail voucherStockDetail=null;
		for (int i = 0; i < datil.size(); i++) {
			Datil = (VoucherTransferOrderDetail) datil
					.get(i);
			if (Datil.getVoucherId() == null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "凭证种类为空!");
			}
			Voucher voucher = voucherDaoImpl.getVoucherByVoucherId(Datil.getVoucherId());
			if (voucher == null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "凭证种类不存在!");
			}
			if (PCPSUtil.isEmpty(Datil.getStartVoucherNo())) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "起始凭证号为空!");
			}
			if (PCPSUtil.isEmpty(Datil.getEndVoucherNo())) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "终止凭证号为空!");
			}

			String StartVoucherNo = Datil.getStartVoucherNo().trim();
			String EndVoucherNo = Datil.getEndVoucherNo().trim();
			if (startseqmap.get(StartVoucherNo) != null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}

			if (endseqmap.get(EndVoucherNo.trim()) != null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行终止号已经重复录入!");
			}

			if (endseqmap.get(StartVoucherNo.trim()) != null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}
			if (startseqmap.get(EndVoucherNo) != null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行终止号已经重复录入!");
			}
			if (isVoucherNo(StartVoucherNo.trim(), startseqmap).endsWith(
					"error")) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}
			if (isVoucherNo(EndVoucherNo.trim(), startseqmap).endsWith("error")) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}
			if (isVoucherNo(StartVoucherNo, startseqmap).endsWith("error")) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}
			if (isVoucherNo(EndVoucherNo, endseqmap).endsWith("error")) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "第" + j + "行起始号已经重复录入!");
			}
			startseqmap.put(StartVoucherNo.trim(), EndVoucherNo.trim());
			endseqmap.put(EndVoucherNo.trim(), StartVoucherNo.trim());
			// 前台得到的数量

			BigInteger tempkcount = new BigInteger(EndVoucherNo.trim())
					.subtract(new BigInteger(StartVoucherNo.trim()));

			tempkcount = tempkcount.add(BigInteger.ONE);
			// 得到库存中本号段的总数
			BigInteger stockcount1 = voucherStockDaoImpl// 凭证号段有误
					.getVoucherStockListTotal(webInput, Datil.getVoucherId(), StartVoucherNo
							.trim(), EndVoucherNo.trim(), null);
			System.out.println(stockcount1);
			if (stockcount1.compareTo(BigInteger.ZERO) == 0) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "本机构库存不存在此凭证号段!或凭证种类不对!");
			}
			BigInteger stockcount2 = voucherStockDaoImpl// 状态
					.getVoucherStockListTotal(webInput, null, StartVoucherNo
							.trim(), EndVoucherNo.trim(), VoucherStock.Status_0);
			if (stockcount2.compareTo(BigInteger.ZERO) == 0) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "此凭证号段库存状态已不是正常状态!");
			}
			BigInteger stockcount = voucherStockDaoImpl
					.getVoucherStockListTotal(webInput, Datil.getVoucherId(),
							StartVoucherNo.trim(), EndVoucherNo.trim(),
							VoucherStock.Status_0);
			if (tempkcount.compareTo(stockcount) != 0) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "请选择此号段对应的凭证种类!或库存状态不是正常状态!");
			}
			VoucherTransferOrderDetail voucherTransferOrderDetail = new VoucherTransferOrderDetail();
			voucherTransferOrderDetail.setTransferOrderId(transferOrderId);
			voucherTransferOrderDetail.setSeqNo(new BigInteger(String
					.valueOf(j)));  
			voucherTransferOrderDetail.setStartVoucherNo(StartVoucherNo.trim());
			voucherTransferOrderDetail.setEndVoucherNo(EndVoucherNo.trim());
			voucherTransferOrderDetail.setVoucherId(Datil.getVoucherId());
			voucherTransferOrderDetail.setCount(tempkcount.intValue());
			voucherTransferOrderDetailBusinessImpl
					.insertVoucherTransferOrderDetail(webInput,
							voucherTransferOrderDetail);
			//将库存状态改为在途
			VoucherStock  voucherStock=null;
			BigInteger sno=new BigInteger(StartVoucherNo.trim());
			int vouchernolength = voucher.getVoucherNoLen().intValue();
			String VoucherNoStr = "";
			for(int k=0;k<tempkcount.intValue();k++){
				voucherStock=new VoucherStock();
				VoucherNoStr = String.format("%0" + vouchernolength + "d",sno);
				voucherStock.setIssueCompanyNo(webInput.getOperBranchNo().substring(0,6));
				voucherStock.setVoucherId(Datil.getVoucherId());
				voucherStock.setVoucherNo(VoucherNoStr);
				VoucherStock voucherStock1=voucherStockDaoImpl.getVoucherStock(voucherStock);				
				voucherStock1.setStatus(VoucherStock.Status_1);
				voucherStockBusinessDaoImpl.updateVoucherStockByStatus(webInput,voucherStock1);
				sno=sno.add(BigInteger.ONE);
				
			}			
			j++;
			//
			
			
		}
		// 迁移明细
		VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
		voucherOrderActionDetail.setTransferOrderId(transferOrderId);
		voucherOrderActionDetail.setOperId(webInput.getOperId());
		voucherOrderActionDetail
				.setInitialStatus(VoucherTransferOrder.Status_0);
		voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl
				.getDatabaseSysTime());
		voucherOrderActionDetail.setEndStatus(VoucherTransferOrder.Status_0);
		voucherOrderActionDetail
				.setActionType(VoucherOrderActionDetail.ACTIONTYPE_0);
		voucherOrderActionDetailDaoImpl
				.insertVoucherOrderActionDetail(voucherOrderActionDetail);
		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "凭证调拨单明细新增",
				voucherTransferOrder, SysOperLog.operType_Add,
				"TransferOrderId:" + voucherTransferOrder.getTransferOrderId());
		return transferOrderId;
	}

	/**
	 * 修改凭证调拨单状态
	 * 
	 * @param VoucherTransferOrder
	 *            凭证调拨单
	 * @throws PCPSApplicationException
	 */
	public void updateVoucherTransferOrderByStatus(PCPSWebInput webInput,
			VoucherTransferOrder voucherTransferOrder)
			throws PCPSApplicationException {
		// 登录用户机构号为空
		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户机构号为NULL");
		}
		// 验证凭证调拨单ID
		if (voucherTransferOrder.getTransferOrderId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调拨单ID为空!");
		}
		// 验证操作人
		if (webInput.getOperId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"用户ID为空!");
		}
		// 验证状态
		if (PCPSUtil.isEmpty(voucherTransferOrder.getStatus())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"状态为空!");
		}
		VoucherTransferOrder voucherTransferOrder1 = voucherTransferOrderDaoImpl
				.getVoucherTransferOrderByTransferOrderId(voucherTransferOrder
						.getTransferOrderId());
		if (voucherTransferOrder1 == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"凭证调拨不存在!");
		}
		String stuts = voucherTransferOrder1.getStatus();
		String status = voucherTransferOrder.getStatus();
		if (status.equals(VoucherTransferOrder.Status_5)) {
			voucherTransferOrder1.setStatus(status);
			if(voucherOrderActionDetailDaoImpl.IsTransferOrderActionDetail(voucherTransferOrder
						.getTransferOrderId(), webInput.getOperId())>0){
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
				    "取消调出人不能和创建人是同一人!请合理分配角色!");
			}
			List<VoucherTransferOrderDetail> datil_list5 = voucherTransferOrderDetailDaoImpl
			.getVoucherTransferOrderDetailListByTransferOrderIdNotPage(
					webInput, voucherTransferOrder.getTransferOrderId());
			if(datil_list5 == null && datil_list5.size()==0) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "调拨明细不存在!");
			}
			for (int i = 0; i < datil_list5.size(); i++) {
				VoucherTransferOrderDetail indetail = datil_list5.get(i);
				String StartVoucherNo = indetail.getStartVoucherNo().trim();// 起始凭证号
				String EndVoucherNo = indetail.getEndVoucherNo().trim();// 终止凭证号
				int Count = indetail.getCount();// 张数
				BigInteger VoucherId = indetail.getVoucherId();// 凭证种类ID
				// 得到入库总数
				BigInteger stocktotal = voucherStockDaoImpl
						.getVoucherStockListByStatusTotal(webInput,
								indetail.getVoucherId(), StartVoucherNo,
								EndVoucherNo, null);
				if (stocktotal.intValue() != Count) {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "凭证号段有误!");
				}
				BigInteger voucherNo = BigInteger.ZERO;
				String vouNo = "";
				Voucher voucher = voucherDaoImpl
						.getVoucherByVoucherId(VoucherId);
				if (voucher == null) {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "凭证种类不存在!");
				}
				int vouchernolength = voucher.getVoucherNoLen().intValue();
				for (int ii = 0; ii < Count; ii++) {
					String cii = String.valueOf(ii);
					voucherNo = (new BigInteger(StartVoucherNo)
							.add(new BigInteger(cii)));
					vouNo = String.format("%0" + vouchernolength + "d",
							voucherNo);
					VoucherStock voucherStock = new VoucherStock();
					voucherStock.setVoucherNo(vouNo);
					voucherStock.setVoucherId(VoucherId);
					voucherStock.setIssueCompanyNo(webInput.getOperBranchNo().substring(0,6));
					VoucherStock voucherStock1 = voucherStockDaoImpl
							.getVoucherStock(voucherStock);
					voucherStock1.setStatus(VoucherStock.Status_0);
					// 修改库存为正常
					voucherStockBusinessDaoImpl.updateVoucherStockByStatus(webInput, voucherStock1);
				}					
	     	}
			
			// 迁移明细
			VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
			voucherOrderActionDetail.setTransferOrderId(voucherTransferOrder
					.getTransferOrderId());
			voucherOrderActionDetail.setOperId(webInput.getOperId());
			voucherOrderActionDetail
					.setInitialStatus(VoucherTransferOrder.Status_0);
			voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl
					.getDatabaseSysTime());
			voucherOrderActionDetail
					.setEndStatus(VoucherTransferOrder.Status_5);
			voucherOrderActionDetail
					.setActionType(VoucherOrderActionDetail.ACTIONTYPE_4);
			voucherOrderActionDetailDaoImpl
					.insertVoucherOrderActionDetail(voucherOrderActionDetail);
		} else if (status.equals(VoucherTransferOrder.Status_4)) {// 拒收--注:要将库存状态在途改为正常
			if(voucherOrderActionDetailDaoImpl.IsTransferOrderActionDetail(voucherTransferOrder
					.getTransferOrderId(), webInput.getOperId())>0){
			      throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
			         "拒绝人不能和（创建人,调出审核人或接收人）是同一人!请合理分配角色!");
		    }
			voucherTransferOrder1.setStatus(status);
			List<VoucherTransferOrderDetail> datil_list = voucherTransferOrderDetailDaoImpl
					.getVoucherTransferOrderDetailListByTransferOrderIdNotPage(
							webInput, voucherTransferOrder.getTransferOrderId());
			if(datil_list == null && datil_list.size()==0) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "调拨明细不存在!");
			}
			for (int i = 0; i < datil_list.size(); i++) {
				VoucherTransferOrderDetail indetail = datil_list.get(i);
				String StartVoucherNo = indetail.getStartVoucherNo().trim();// 起始凭证号
				String EndVoucherNo = indetail.getEndVoucherNo().trim();// 终止凭证号
				int Count = indetail.getCount();// 张数
				BigInteger VoucherId = indetail.getVoucherId();// 凭证种类ID
				// 得到入库总数
				BigInteger stocktotal = voucherStockDaoImpl
						.getVoucherStockListByStatusTotal(webInput,
								indetail.getVoucherId(), StartVoucherNo,
								EndVoucherNo, null);
				if (stocktotal.intValue() != Count) {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "凭证号段有误!");
				}
				BigInteger voucherNo = BigInteger.ZERO;
				String vouNo = "";
				Voucher voucher = voucherDaoImpl
						.getVoucherByVoucherId(VoucherId);
				if (voucher == null) {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "凭证种类不存在!");
				}
				int vouchernolength = voucher.getVoucherNoLen().intValue();
				for (int ii = 0; ii < Count; ii++) {
					String cii = String.valueOf(ii);
					voucherNo = (new BigInteger(StartVoucherNo)
							.add(new BigInteger(cii)));
					vouNo = String.format("%0" + vouchernolength + "d",
							voucherNo);
					VoucherStock voucherStock = new VoucherStock();
					voucherStock.setVoucherNo(vouNo);
					voucherStock.setVoucherId(VoucherId);
					voucherStock.setIssueCompanyNo(webInput.getOperBranchNo().substring(0,6));
					VoucherStock voucherStock1 = voucherStockDaoImpl
							.getVoucherStock(voucherStock);
					voucherStock1.setStatus(VoucherStock.Status_0);
					// 修改库存为正常
					voucherStockBusinessDaoImpl.updateVoucherStockByStatus(webInput, voucherStock1);
				}
			}
			// 迁移明细
			if (stuts.equals(VoucherTransferOrder.Status_1)) {
				VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
				voucherOrderActionDetail
						.setTransferOrderId(voucherTransferOrder
								.getTransferOrderId());
				voucherOrderActionDetail.setOperId(webInput.getOperId());
				voucherOrderActionDetail
						.setInitialStatus(VoucherTransferOrder.Status_1);
				voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl
						.getDatabaseSysTime());
				voucherOrderActionDetail
						.setEndStatus(VoucherTransferOrder.Status_4);
				voucherOrderActionDetail
						.setActionType(VoucherOrderActionDetail.ACTIONTYPE_4);
				voucherOrderActionDetailDaoImpl
						.insertVoucherOrderActionDetail(voucherOrderActionDetail);
			} else {
				VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
				voucherOrderActionDetail
						.setTransferOrderId(voucherTransferOrder
								.getTransferOrderId());
				voucherOrderActionDetail.setOperId(webInput.getOperId());
				voucherOrderActionDetail
						.setInitialStatus(VoucherTransferOrder.Status_2);
				voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl
						.getDatabaseSysTime());
				voucherOrderActionDetail
						.setEndStatus(VoucherTransferOrder.Status_4);
				voucherOrderActionDetail
						.setActionType(VoucherOrderActionDetail.ACTIONTYPE_4);
				voucherOrderActionDetailDaoImpl
						.insertVoucherOrderActionDetail(voucherOrderActionDetail);
			}
		} else if (status.equals(VoucherTransferOrder.Status_1)) {
			if(voucherOrderActionDetailDaoImpl.IsTransferOrderActionDetail(voucherTransferOrder
					.getTransferOrderId(), webInput.getOperId())>0){
			      throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
			         "审核不能和（创建人,接收人）是同一人!请合理分配角色!");
		    }
			if (status.equals(VoucherStock.Status_1)) {
				voucherTransferOrder1.setStatus(VoucherTransferOrder.Status_1);
				List<VoucherTransferOrderDetail> datillist = voucherTransferOrderDetailDaoImpl
						.getVoucherTransferOrderDetailListByTransferOrderIdNotPage(
								webInput, voucherTransferOrder
										.getTransferOrderId());
				
				if (datillist != null && datillist.size() > 0) {
					VoucherStockDetail voucherStockDetail = null;
					VoucherTransferOrderDetail indetail = null;
					// 发卡商
					IssueCompany ic = issueCompanyDaoImpl
							.getIssueCompanyByIssueCompanyNo(webInput.getOperBranchNo()
									.substring(0, 6));
					String branchno="";//机构号
					for (int i = 0; i < datillist.size(); i++) {
						indetail = datillist.get(i);
						String StartVoucherNo = indetail.getStartVoucherNo();// 起始凭证号
						String EndVoucherNo = indetail.getEndVoucherNo();// 终止凭证号
						int Count = indetail.getCount();// 张数
						BigInteger VoucherId = indetail.getVoucherId();// 凭证种类ID
						// 得到入库总数
						BigInteger stocktotal = voucherStockDaoImpl
								.getVoucherStockListByStatusTotal(webInput,
										VoucherId, StartVoucherNo.trim(),
										EndVoucherNo.trim(), VoucherStock.Status_1);
						if (stocktotal.intValue() != Count) {
							throw new OrganApplicationException(
									OrganRespCode.RC_ARGS_NULL, "",
									"凭证号段有误!或状态已不是有效状态!");
						}
						BigInteger voucherNo = BigInteger.ZERO;
						String vouNo = "";
						Voucher voucher = voucherDaoImpl
								.getVoucherByVoucherId(VoucherId);
						if (voucher == null) {
							throw new OrganApplicationException(
									OrganRespCode.RC_ARGS_NULL, "", "凭证种类不存在!");
						}
						int vouchernolength = voucher.getVoucherNoLen()
								.intValue();
						VoucherStock voucherStock = null;
						for (int ii = 0; ii < Count; ii++) {
							String cii = String.valueOf(ii);
							voucherNo = (new BigInteger(StartVoucherNo)
									.add(new BigInteger(cii)));
							vouNo = String.format("%0" + vouchernolength + "d",
									voucherNo);

							voucherStock = new VoucherStock();
							voucherStock.setVoucherNo(vouNo);
							voucherStock.setVoucherId(VoucherId);
							voucherStock = voucherStockDaoImpl
									.getVoucherStock(voucherStock);

							if (voucherStock == null) {
								throw new OrganApplicationException(
										OrganRespCode.RC_ARGS_NULL, "",
										"凭证号不存在!");
							}
							voucherStock.setStatus(VoucherStock.Status_1);
							// 修改库存为在途
							voucherStockDaoImpl
									.updateVoucherStockByStatus(voucherStock);
						}
						if(voucherTransferOrder1.getFromBranchNo()!=null)
							branchno=voucherTransferOrder1.getFromBranchNo().trim();
						else
							branchno=voucherTransferOrder1.getToBranchNo().trim();
						// 凭证出入库明细
						/*voucherStockDetail = new VoucherStockDetail();
						voucherStockDetail.setIoOrderId(voucherTransferOrder1.getTransferOrderId());
						
						voucherStockDetail.setBranchNo(branchno);
						voucherStockDetail.setTranDate(ic.getTranDate());
						voucherStockDetail.setTranTime(pcpsCommonDaoImpl.getDatabaseSysTime());
						voucherStockDetail.setIssueCompanyNo(voucherTransferOrder1.getIssueCompanyNo());
						voucherStockDetail.setVoucherId(indetail.getVoucherId());
						voucherStockDetail.setStartVoucherNo(indetail.getStartVoucherNo());
						voucherStockDetail.setEndVoucherNo(indetail.getEndVoucherNo());
						voucherStockDetail.setCount(indetail.getCount());
						voucherStockDetail.setTranType(VoucherStockDetail.Status_2);
						voucherStockDetail.setOperId(webInput.getOperId());
						voucherStockDetailBusinessDaoImpl.insertVoucherStockDetail(webInput, voucherStockDetail);*/
					}
					// 迁移明细
					VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
					voucherOrderActionDetail
							.setTransferOrderId(voucherTransferOrder
									.getTransferOrderId());
					voucherOrderActionDetail.setOperId(webInput.getOperId());
					voucherOrderActionDetail
							.setInitialStatus(VoucherTransferOrder.Status_0);
					voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl.getDatabaseSysTime());
					voucherOrderActionDetail.setEndStatus(VoucherTransferOrder.Status_1);
					voucherOrderActionDetail
							.setActionType(VoucherOrderActionDetail.ACTIONTYPE_1);
					voucherOrderActionDetailDaoImpl
							.insertVoucherOrderActionDetail(voucherOrderActionDetail);
					
				} else {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "调拨有误!暂无调拨明细!");
				}
			}
		}
		//voucherTransferOrder1.setAuthTime(pcpsCommonDaoImpl.getDatabaseSysTime());
		voucherTransferOrder1.setRemark(voucherTransferOrder.getRemark());
		// 审核人
		//voucherTransferOrder1.setAuthOperId(webInput.getOperId());
		// 修改
		voucherTransferOrderDaoImpl
				.updateVoucherTransferOrderByStatus(voucherTransferOrder1);
		// 修改数据库操作日志
		insertRecordingOperationLog(webInput, "凭证调拨单修改", voucherTransferOrder1,
				SysOperLog.operType_Edit, "TransferOrderId:"
						+ voucherTransferOrder.getTransferOrderId());
	}

	/**
	 * 修改凭证调拨单状态--2-接收
	 * 
	 * @param VoucherTransferOrder
	 *            凭证调拨单
	 * @throws PCPSApplicationException
	 */
	public void updateVoucherTransferOrderByStatusBy2(PCPSWebInput webInput,
			VoucherTransferOrder voucherTransferOrder)
			throws PCPSApplicationException {
		// 登录用户机构号为空
		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户机构号为NULL");
		}
		// 验证凭证调拨单ID
		if (voucherTransferOrder.getTransferOrderId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调拨单ID为空!");
		}
		// 验证操作人
		if (webInput.getOperId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"用户ID为空!");
		}
		// 验证备注
		if (PCPSUtil.isEmpty(voucherTransferOrder.getRemark())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"备注为空!");
		}
		// 验证状态
		if (PCPSUtil.isEmpty(voucherTransferOrder.getStatus())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"状态为空!");
		}
		VoucherTransferOrder voucherTransferOrder1 = voucherTransferOrderDaoImpl
				.getVoucherTransferOrderByTransferOrderId(voucherTransferOrder
						.getTransferOrderId());
		if (voucherTransferOrder1 == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"凭证调拨不存在!");
		}
		String status = voucherTransferOrder.getStatus();
		String status1 = voucherTransferOrder1.getStatus();
		if (status1.equals(VoucherTransferOrder.Status_1)) {
			if(voucherOrderActionDetailDaoImpl.IsTransferOrderActionDetail(voucherTransferOrder
					.getTransferOrderId(), webInput.getOperId())>0){
			      throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
			         " 接收人不能和（创建人,调出审核人）是同一人!请合理分配角色!");
		    }
			if (!status.equals(VoucherTransferOrder.Status_2)) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "凭证调拨状态无效!不能做该操作!");
			} else {
				if (status.equals(VoucherTransferOrder.Status_2)) {
					voucherTransferOrder1
							.setStatus(VoucherTransferOrder.Status_2);
					List<VoucherTransferOrderDetail> datillist = voucherTransferOrderDetailDaoImpl
							.getVoucherTransferOrderDetailListByTransferOrderIdNotPage(
									webInput, voucherTransferOrder
											.getTransferOrderId());
					if (datillist != null) {
						for (int i = 0; i < datillist.size(); i++) {
							VoucherTransferOrderDetail indetail = datillist
									.get(i);
							String StartVoucherNo = indetail
									.getStartVoucherNo();// 起始凭证号
							String EndVoucherNo = indetail.getEndVoucherNo();// 终止凭证号
							int Count = indetail.getCount();// 张数
							BigInteger VoucherId = indetail.getVoucherId();// 凭证种类ID
							// 得到入库总数
							BigInteger stocktotal = voucherStockDaoImpl
									.getVoucherStockListByStatusTotal(webInput,
											VoucherId, StartVoucherNo,
											EndVoucherNo, VoucherStock.Status_1);
							if (stocktotal.intValue() != Count) {
								throw new OrganApplicationException(
										OrganRespCode.RC_ARGS_NULL, "",
										"凭证号段有误!");
							}

						}
						// 迁移明细
						VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
						voucherOrderActionDetail
								.setTransferOrderId(voucherTransferOrder
										.getTransferOrderId());
						voucherOrderActionDetail
								.setOperId(webInput.getOperId());
						voucherOrderActionDetail
								.setInitialStatus(VoucherTransferOrder.Status_1);
						voucherOrderActionDetail
								.setActionTime(pcpsCommonDaoImpl
										.getDatabaseSysTime());
						voucherOrderActionDetail
								.setEndStatus(VoucherTransferOrder.Status_2);
						voucherOrderActionDetail
								.setActionType(VoucherOrderActionDetail.ACTIONTYPE_2);
						voucherOrderActionDetailDaoImpl
								.insertVoucherOrderActionDetail(voucherOrderActionDetail);
					} else {
						throw new OrganApplicationException(
								OrganRespCode.RC_ARGS_NULL, "", "调拨有误!暂无调拨明细!");
					}
				} else {
					voucherTransferOrder1
							.setStatus(VoucherTransferOrder.Status_4);
				}
				voucherTransferOrder1.setAuthTime(pcpsCommonDaoImpl
						.getDatabaseSysTime());
			}
		}

		voucherTransferOrder1.setRemark(voucherTransferOrder.getRemark());
		// 审核人
		voucherTransferOrder1.setAuthOperId(webInput.getOperId());
		// 修改
		voucherTransferOrderDaoImpl
				.updateVoucherTransferOrderByStatus(voucherTransferOrder1);
		// 修改数据库操作日志
		insertRecordingOperationLog(webInput, "凭证调拨单修改", voucherTransferOrder1,
				SysOperLog.operType_Edit, "TransferOrderId:"
						+ voucherTransferOrder.getTransferOrderId());
	}

	/**
	 * 修改凭证调拨单状态--3-接收确认(M)
	 * 
	 * @param VoucherTransferOrder
	 *            凭证调拨单
	 * @throws PCPSApplicationException
	 */
	public void updateVoucherTransferOrderByStatusBy3(PCPSWebInput webInput,
			VoucherTransferOrder voucherTransferOrder)
			throws PCPSApplicationException {
		// 登录用户机构号为空
		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户机构号为NULL");
		}
		// 验证凭证调拨单ID
		if (voucherTransferOrder.getTransferOrderId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"调拨单ID为空!");
		}
		// 验证操作人
		if (webInput.getOperId() == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"用户ID为空!");
		}
		VoucherTransferOrder voucherTransferOrder1 = voucherTransferOrderDaoImpl
				.getVoucherTransferOrderByTransferOrderId(voucherTransferOrder
						.getTransferOrderId());
		if (voucherTransferOrder1 == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"凭证调拨不存在!");
		}
		if(voucherOrderActionDetailDaoImpl.IsTransferOrderActionDetail(voucherTransferOrder
				.getTransferOrderId(), webInput.getOperId())>0){
		      throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
		         " 接收确认人不能和（创建人,调出审核人,接收人）是同一人!请合理分配角色!");
	    }
		/*
		 * String status1=voucherTransferOrder1.getStatus();
		 * //System.out.println("=="+status1);
		 * if(!status1.equals(VoucherTransferOrder.Status_2)){ throw new
		 * OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
		 * "凭证调拨状态无效!不能做该操作!"); }
		 */
		voucherTransferOrder1.setStatus(VoucherTransferOrder.Status_3);
		//voucherTransferOrder1.setAuthTime(pcpsCommonDaoImpl.getDatabaseSysTime());
		voucherTransferOrder1.setRemark(voucherTransferOrder.getRemark());
		// 审核人
		//voucherTransferOrder1.setAuthOperId(webInput.getOperId());
		// 修改
		voucherTransferOrderDaoImpl
				.updateVoucherTransferOrderByStatus(voucherTransferOrder1);

		String issbranchno = null;
		String salebranchno = null;
		SysBranch sysbranch = sysBranchDaoImpl
				.getSysBranchByBranchNo(voucherTransferOrder1.getToBranchNo());
		if (sysbranch.getBranchType().equals(SysBranch.SYSBRANCH_ISSUEBRANCH))
			issbranchno = voucherTransferOrder1.getToBranchNo();
		else if (sysbranch.getBranchType().equals(
				SysBranch.SYSBRANCH_SALEBRANCH))
			salebranchno = voucherTransferOrder1.getToBranchNo();
		List<VoucherTransferOrderDetail> datillist = voucherTransferOrderDetailDaoImpl
				.getVoucherTransferOrderDetailListByTransferOrderIdNotPage(
						webInput, voucherTransferOrder.getTransferOrderId());
		VoucherStockDetail voucherStockDetail = null;
		VoucherTransferOrderDetail indetail = null;
		// 发卡商
		IssueCompany ic = issueCompanyDaoImpl
				.getIssueCompanyByIssueCompanyNo(webInput.getOperBranchNo()
						.substring(0, 6));
		for (int i = 0; i < datillist.size(); i++) {
			indetail = datillist.get(i);
			String StartVoucherNo = indetail.getStartVoucherNo();// 起始凭证号
			int Count = indetail.getCount();// 张数
			BigInteger VoucherId = indetail.getVoucherId();// 凭证种类ID
			Voucher voucher = voucherDaoImpl.getVoucherByVoucherId(VoucherId);
			if (voucher == null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "凭证种类不存在!");
			}
			int vouchernolength = voucher.getVoucherNoLen().intValue();
			String VoucherNoStr = "";
			for (int ii = 0; ii < Count; ii++) {
				String cii = String.valueOf(ii);
				BigInteger VoucherNo = (new BigInteger(StartVoucherNo)
						.add(new BigInteger(cii)));
				VoucherNoStr = String.format("%0" + vouchernolength + "d",
						VoucherNo);
				VoucherStock voucherStock = new VoucherStock();
				voucherStock.setVoucherNo(VoucherNoStr);
				voucherStock.setVoucherId(VoucherId);
				voucherStock.setIssueCompanyNo(webInput.getOperBranchNo().substring(0,6));
				// 得到入库单ID
				VoucherStock Isvoucherstock = voucherStockDaoImpl
						.getVoucherStock(voucherStock);
				if (Isvoucherstock == null) {
					throw new OrganApplicationException(
							OrganRespCode.RC_ARGS_NULL, "", "凭证号已经不存在!");
				}
				Isvoucherstock.setStatus(VoucherStock.Status_0);
				Isvoucherstock.setIssueBranchNo(issbranchno);
				Isvoucherstock.setSaleBranchNo(salebranchno);

				// 修改库存
				voucherStockBusinessDaoImpl.updateVoucherStockByStatus(
						webInput, Isvoucherstock);
				// System.out.println("==============修改库存");
			}
			

			
			// 凭证出入库明细
			voucherStockDetail = new VoucherStockDetail();
			voucherStockDetail.setIoOrderId(voucherTransferOrder1.getTransferOrderId());			
			
			voucherStockDetail.setTranDate(ic.getTranDate());
			voucherStockDetail.setTranTime(pcpsCommonDaoImpl.getDatabaseSysTime());
			voucherStockDetail.setIssueCompanyNo(voucherTransferOrder1.getIssueCompanyNo());
			voucherStockDetail.setVoucherId(indetail.getVoucherId());
			voucherStockDetail.setStartVoucherNo(indetail.getStartVoucherNo());
			voucherStockDetail.setEndVoucherNo(indetail.getEndVoucherNo());
			voucherStockDetail.setCount(indetail.getCount());
			voucherStockDetail.setTranType(VoucherStockDetail.Status_2);
			/*VoucherOrderActionDetail voucherOrderActionDetail=voucherOrderActionDetailDaoImpl.getVoucherOrderActionDetailBycon(voucherTransferOrder1.getTransferOrderId(), VoucherOrderActionDetail.ACTIONTYPE_0, VoucherOrderActionDetail.ACTIONTYPE_0, VoucherOrderActionDetail.ACTIONTYPE_0);
			if(voucherOrderActionDetail==null){
				  throw new OrganApplicationException(
				         OrganRespCode.RC_ARGS_NULL, "", "迁移明细无调拨单创建!");
			}*/
			voucherStockDetail.setOperId(voucherTransferOrder1.getOperId());
			voucherStockDetail.setBranchNo(voucherTransferOrder1.getFromBranchNo());
			voucherStockDetailBusinessDaoImpl.insertVoucherStockDetail(webInput, voucherStockDetail);	
			
			
			// 凭证出入库明细
			voucherStockDetail = new VoucherStockDetail();
			voucherStockDetail.setIoOrderId(voucherTransferOrder1.getTransferOrderId());
			
			voucherStockDetail.setBranchNo(webInput.getOperBranchNo());
			voucherStockDetail.setTranDate(ic.getTranDate());
			voucherStockDetail.setTranTime(pcpsCommonDaoImpl.getDatabaseSysTime());
			voucherStockDetail.setIssueCompanyNo(voucherTransferOrder1.getIssueCompanyNo());
			voucherStockDetail.setVoucherId(indetail.getVoucherId());
			voucherStockDetail.setStartVoucherNo(indetail.getStartVoucherNo());
			voucherStockDetail.setEndVoucherNo(indetail.getEndVoucherNo());
			voucherStockDetail.setCount(indetail.getCount());
			voucherStockDetail.setTranType(VoucherStockDetail.Status_1);
			voucherStockDetail.setOperId(webInput.getOperId());
			voucherStockDetailBusinessDaoImpl.insertVoucherStockDetail(webInput, voucherStockDetail);				
			
			
			
		}
		// 迁移明细
		VoucherOrderActionDetail voucherOrderActionDetail = new VoucherOrderActionDetail();
		voucherOrderActionDetail.setTransferOrderId(voucherTransferOrder
				.getTransferOrderId());
		voucherOrderActionDetail.setOperId(webInput.getOperId());
		voucherOrderActionDetail
				.setInitialStatus(VoucherTransferOrder.Status_2);
		voucherOrderActionDetail.setActionTime(pcpsCommonDaoImpl
				.getDatabaseSysTime());
		voucherOrderActionDetail.setEndStatus(VoucherTransferOrder.Status_3);
		voucherOrderActionDetail
				.setActionType(VoucherOrderActionDetail.ACTIONTYPE_3);
		voucherOrderActionDetailDaoImpl
				.insertVoucherOrderActionDetail(voucherOrderActionDetail);
		// 修改数据库操作日志
		insertRecordingOperationLog(webInput, "凭证调拨单修改", voucherTransferOrder1,
				SysOperLog.operType_Edit, "TransferOrderId:"
						+ voucherTransferOrder.getTransferOrderId());
	}

	private void insertRecordingOperationLog(PCPSWebInput webInput,
			String logName, VoucherTransferOrder obj, String operType,
			String lastFieldName) throws PCPSApplicationException {
		String logRemark = PCPSUtil.RecordingOperationLog(obj, lastFieldName);
		if (!PCPSUtil.isEmpty(logRemark)) {
			// 插入数据库日志
			SysOperLog sysOperLog = new SysOperLog();
			if (webInput != null && webInput.getOperId() != null) {
				sysOperLog.setOperId(webInput.getOperId());
				sysOperLog.setOperType(operType);
				sysOperLog.setLogName(logName);
				if (webInput != null) {
					sysOperLog.setIpAddress(webInput.getIpAddress());
				}
				if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
					sysOperLog.setIssueCompanyNo(webInput.getOperBranchNo()
							.substring(0, 6));
					sysOperLog.setBranchNo(webInput.getOperBranchNo());
				}
				sysOperLog.setRemark(logRemark);
				sysOperLogDaoImpl.insertSysOperLog(sysOperLog);
			}
		}
	}

	/**
	 * 验证号段是否重复
	 */
	@SuppressWarnings("unchecked")
	private String isVoucherNo(String Voucherno, Map map) {
		Iterator ite = map.entrySet().iterator();
		while (ite.hasNext()) {
			Map.Entry<Object, Object> entry = (Entry<Object, Object>) ite
					.next();
			Object key = entry.getKey();
			Object value = entry.getValue();
			BigInteger bigkey = new BigInteger(key.toString());
			BigInteger bigvalue = new BigInteger(value.toString());
			BigInteger bigvoucherno = new BigInteger(Voucherno);
			if (bigvoucherno.intValue() >= bigkey.intValue()
					&& bigvoucherno.intValue() <= bigvalue.intValue())
				return "error";
		}
		return "";
	}
}
